Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search in linked lists using a BTree #603

Merged
merged 10 commits into from
Sep 13, 2024
Merged

Conversation

4l0n50
Copy link
Contributor

@4l0n50 4l0n50 commented Sep 6, 2024

Replaces the linear search in the linked lists by searching on auxiliary Btrees of accounts and storage. Closes #391.

@github-actions github-actions bot added the crate: evm_arithmetization Anything related to the evm_arithmetization crate. label Sep 6, 2024
@Nashtare Nashtare added this to the Performance Tuning milestone Sep 6, 2024
Copy link
Collaborator

@Nashtare Nashtare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, the approach for searching items is much cleaner than what I had started doing.

I think the low performance improvement we've noticed is coming from the fact that you don't have a way to know the length post insertion / deletion, hence the needless operations. We should see additional gains once this is addressed.

Also any reason why you didn't touch the AccessedAddresses / AccessedStorageKeys access lists? They use the LinkedList approach and also suffer from linear search.

evm_arithmetization/src/generation/mpt.rs Show resolved Hide resolved
evm_arithmetization/src/generation/state.rs Outdated Show resolved Hide resolved
Comment on lines 595 to 599
let storage_mem = self
.memory
.get_preinit_memory(Segment::StorageLinkedList);
self.storage.extend(
StorageLinkedList::from_mem_and_segment(&storage_mem, Segment::StorageLinkedList)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a bit heavy in terms of allocation, why don't we instead update the new accounts / storage maps as we process the initial tries in preinitialize_linked_lists_and_txn_and_receipt_mpts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and also because of the iteration below which is linear and may be slow for large batches

evm_arithmetization/src/generation/state.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/generation/linked_list.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/generation/prover_input.rs Outdated Show resolved Hide resolved
evm_arithmetization/src/generation/prover_input.rs Outdated Show resolved Hide resolved
@4l0n50
Copy link
Contributor Author

4l0n50 commented Sep 9, 2024

Also any reason why you didn't touch the AccessedAddresses / AccessedStorageKeys access lists? They use the LinkedList approach and also suffer from linear search.

They follow a slightly different logic that we already had struggle with when trying to merge access lists with linked lists in the kernel. But yes, this should be tackled in the future. I created issue #611

Copy link
Collaborator

@Nashtare Nashtare left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Alonso, LGTM! It now takes around ~500/700ns on my machine for searches, instead of up to 1.5ms for large batches on develop.

@Nashtare Nashtare merged commit 3ef67fd into develop Sep 13, 2024
17 checks passed
@Nashtare Nashtare deleted the refactor_linked_list_search branch September 13, 2024 16:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
crate: evm_arithmetization Anything related to the evm_arithmetization crate.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

perf(continuations): linked list search should run in sublinear time
2 participants